﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using KnowWare.Model;

/*
 * Denne fil benyttes ikke
 */

namespace KnowWareBeta
{
    /// <summary>
    /// Interaction logic for PlaceringsVindue.xaml
    /// </summary>
    public partial class PlaceringsVindue : Window
    {
        private Label grabbedLabel;
        private List<Hold> holdListe;

        public PlaceringsVindue(List<Hold> holdListe)
        {
            this.holdListe = holdListe;

            InitializeComponent();

            RebuildWindow();
        }

        private void RebuildWindow()
        {
            foreach (Hold hold in holdListe)
            {
                PlaceringsBox box = new PlaceringsBox();
                box.label.Content = hold.HoldNavn;
                box.btn_up.Click += new RoutedEventHandler(btn_up_Click);
                box.btn_down.Click += new RoutedEventHandler(btn_down_Click);
                // lbl.MouseDown += new MouseButtonEventHandler(DragStart);
                // lbl.MouseUp += new MouseButtonEventHandler(DragStop);
                // lbl.MouseMove += new MouseEventHandler(DragMove);

                sp_indhold.Children.Add(box);
            }
        }

        private int FindIndex(string holdNavn)
        {
            int i = 0;
            foreach (Hold hold in holdListe)
            {
                if (hold.HoldNavn == holdNavn)
                {
                    break;
                }
                i++;
            }
            return i;
        }

        private void btn_up_Click(object sender, RoutedEventArgs e)
        {
            PlaceringsBox box = (PlaceringsBox)((Button)sender).Parent;
            string holdNavn = box.label.Content.ToString();
            int index = FindIndex(holdNavn);
            
            if (index == 0)
            {
                return;
            }

            List<Hold> newList = new List<Hold>();
            newList.AddRange(holdListe);
            foreach (Hold hold in holdListe) {
                if (hold.HoldNavn == holdNavn) {
                    newList.Remove(hold);
                    newList.Insert(index - 1, hold);
                }
            }
        }

        private void btn_down_Click(object sender, RoutedEventArgs e)
        {

        }

        private void DragStart(object sender, MouseEventArgs e)
        {
            grabbedLabel = (Label)sender;
        }

        private void DragStop(object sender, MouseEventArgs e)
        {
            List<Hold> nyListe = new List<Hold>();

            grabbedLabel = null;
        }

        private void DragMove(object sender, MouseEventArgs e)
        {
            if (grabbedLabel == null)
            {
                return;
            }
        }
    }
}
